package com.horizon.config;

import com.horizon.balance.ImLoadBalance;
import com.horizon.util.SpringContextUtil;
import com.horizon.zk.CuratorZKClient;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ZKClientConfig implements ApplicationContextAware {
    @Value("127.0.0.1:2181")
    private String zkConnect;
    @Value("300000")
    private String zkSessionTimeout;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.setContext(applicationContext);
    }

    @Bean(name="curatorZKClient")
    public CuratorZKClient curatorZKClient() {
        return new CuratorZKClient(zkConnect);
    }

    @Bean(name = "imLoadBalance")
    public ImLoadBalance imLoadBalance(CuratorZKClient curatorZKClient)
    {

        return new ImLoadBalance( curatorZKClient);
    }
}
